<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div class="box">
        <p class="p1">这是p1</p> 
               
    </div>
    <input type="text" class="input">
    <br>
    <button onclick="insertP2()">插入新的p标签</button>
    <button onclick="changeP()">修改p1内容</button>

    <script>
        var inputeEl = document.querySelector('.input');
        var p1El = document.querySelector('.p1');
        var boxEl = document.querySelector('.box');
         
        function changeP(){
            console.log(inputeEl.value);
            p1El.innerHTML = inputeEl.value;
        }
        // innerHTML 会把原来的内容全部“替换”掉，所以导致之前绑定的事件失效！！
        function insertP(){
            var pHtml = '<p>这是p2</p>';
            // innerHTML 被重新赋值 是完全替换
            boxEl.innerHTML = boxEl.innerHTML+ pHtml;
        }
        // 使用append追加
        function insertP2(){
           var pDom = document.createElement('p');
           pDom.innerText = '这是p2标签';
           // 追加
           boxEl.appendChild(pDom);  
        }
    </script>
</body>
</html>